﻿/****writed by zhongrui at 200160329***/
; (function ($) {
	$.fn.zCheck = function (options) {
		if (!options) {
			options = [
				{ text: "是", value: true },
				{ text: "否", value: false }
			]
		}

		return this.each(function () {
			var $input = $(this);
			var name = $input.attr("name");
			var html = "";
			var htmltemplate = '<span><i class="stuChecked" data-name="{name}" data-val="{value}"></i>{text}</span>';

			for (var i = 0; i < options.length; i++) {
				html += htmltemplate.replace("{value}", options[i].value).replace("{text}", options[i].text).replace("{name}", name);
			}

			$input.hide();
			$input.after(html);//和原先的input同父元素
			var $parent = $input.parent();
			//冒泡时间绑定，设置原先的input
			$parent.on("click", ".stuChecked[data-name=" + name + "]", function () {
				var $this = $(this)
				$parent.find('.checked').removeClass('checked');
				$this.addClass('checked');
				var checkVal = $this.data('val');
				$parent.find('input[name="' + name + '"]').val(checkVal);
			});
		});
	}
})(jQuery);